package erfgame.core.xml;

import java.util.List;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;

public class ListHandlingXMLFactoryProxy<E> implements ObjectXMLFactory<List<E>> {
	private String elementName;
	private ObjectXMLFactory<E> xmlFactory;
	
	public ListHandlingXMLFactoryProxy( String elementName, ObjectXMLFactory<E> xmlFactory ) {
		this.elementName = elementName;
		this.xmlFactory = xmlFactory;
	}

	public Node toXML(List<E> objects, Document document) {
		Element element = document.createElement(elementName);
		for( E object : objects ) {
			Node objectNode = xmlFactory.toXML(object, document);
			element.appendChild(objectNode);
		}
		return element;
	}
}
